package com.api.oa.exception;


import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
class GlobalExceptionHandler {
    /**
     * 处理其他异常
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = DataAccessException.class)
    @ResponseBody
    public MyResult exceptionHandler(HttpServletRequest req, Exception e){
        MyResult result = new MyResult();
        result.setError(2);
        result.setMessage(e.getMessage());
        e.printStackTrace();
        return result;
    }
}
